eturn-Path: piet@cs.ruu.nl eceived: from unido.informatik.uni-dortmund.de by gorbi.informatik.uni-dortmund.de id AA04891; Mon, 7 Oct 91 11:35:20 +0100 eceived: from ruuinf.cs.ruu.nl by unido.informatik.uni-dortmund.de with SMTP (5.65+/UNIDO-2.0.4.d) via EUnet for gorbi.informatik.uni-dortmund.de id AA12353; Mon, 7 Oct 91 11:31:05 +0100 eceived: from gnu.cs.ruu.nl by ruuinf.cs.ruu.nl with SMTP (5.61+/IDA-1.2.8) id AA25657; Mon, 7 Oct 91 12:15:53 +0100 eceived: by alchemy.cs.ruu.nl (15.11/15.6) id AA20318; Mon, 7 Oct 91 11:34:15 -0100 ate: Mon, 7 Oct 91 11:34:15 -0100 From: Piet van Oostrum essage-Id: <9110071034.AA20318@alchemy.cs.ruu.nl> o: heitkoet (Joerg Heitkoetter) ubject: Re: Fancy Latex Headers - Please Help ewsgroups: comp.text.tex n-Reply-To: <3853@laura.UUCP> rganization: Dept of Computer Science, Utrecht University, The Netherlands ere is the (new) doc file for fancyheadings.sty: ere is a documentstylestyle option that allows you to customize your age headers and footers in an easy way. It combines features that were eparately available in other pagestyles, without introducing much omplexity. You can define: - three-part headers and footers - rules in header and footer - headers and footers wider than \textwidth - multiline headers and footers - separate headers and footers for even and odd pages - separate headers and footers for chapter pages o use this pagestyle, you must include the ``fancyheadings'' style ption in your \documentstyle, and issue the \pagestyle{fancy} command. he \pagestyle{fancy} command should be issued after any changes made to textwidth. he page layout will be as follows: LHEAD CHEAD RHEAD ----------------------------------- (rule) page body ----------------------------------- (rule) LFOOT CFOOT RFOOT he L-fields will be leftadjusted, the C-fields centered and the -fields rightadjusted. ach of the six fields and the two rules can be defined separately. imple use: he header and footer fields can be defined by commands \lhead{LHEAD} nd so on for the other fields. If the field depends on something in the ocument (e.g. section titles) you must in general use the \markboth and markright commands, otherwise a title may end on the wrong page. You an do this e.g. by redefining the commands \chaptermark, \sectionmark nd so on (see example below). The defaults for these marks are as in he standard pagestyles. The marks can be put into a header or footer ield by referencing \leftmark and \rightmark. ules in header and footer he thickness of the rules below the header and above the footer can be hanged by redefining the length parameters \headrulewidth (default .4pt) and \footrulewidth (default 0). These may be redefined by the setlength command. A thickness of 0pt makes the rule invisible. f you want to make more complicated changes, you have to redefine the ommands \headrule and/or \footrule. eaders and footers wider than \textwidth he headers and footers are set in a box of width \headwidth. The efault for this is the value of \textwidth. You can make it wider (or maller) by redefining \headwidth with the \setlength or \addtolength ommand. The headers and footers will stick out the page on the same ide as the marginal notes. For example to include the marginal notes, dd both \marginparsep and \marginparwidth to \headwidth (see also the xample below). ultiline headers and footers ach of the six fields is set in an appropriate parbox, so you can put a ultiline part in it with the \\ command. It is also possible to put xtra space in it with the \vspace command. Note that if you do this you ill probably have to increase the \headheight or \footskip lengths. eparate headers and footers for even and odd pages f you want the headers and footers to be different on even- and dd-numbered pages in the ``twoside'' style, the field-defining macros an be given an optional argument, to be used on the even-numbered ages, like \lhead[EVEN-LHEAD]{ODD-LHEAD}. eparate headers and footers for chapter pages aTeX gives a \thispagestyle{plain} command for the first page of the ocument, the first page of each chapter and a couple of other pages. It ight be incompatible with your pagestyle. In this case you can use a lightly different version of the pagestyle, called \pagestyle{fancyplain}. his pagestyle redefines the pagestyle ``plain'' to also use pagestyle `fancy'' with the following modifications: - the thicknesses of the rules is defined by \plainheadrulewidth and \plainfootrulewidth (both default 0). - the 6 fields may be defined separately for the plain pages by giving them the value \fancyplain{PLAIN-VALUE}{NORMAL-VALUE}. This construct may be used in both the optional argument and the normal argument. Thus \lhead[\fancyplain{F1}{F2}]{\fancyplain{F3}{F4}} specifies the LHEAD value in a two-sided document: F1 on an even-numbered ``plain'' page F2 on an even-numbered normal page F3 on an odd-numbered ``plain'' page F4 on an odd-numbered normal page. efaults: headrulewidth 0.4pt footrulewidth 0pt plainheadrulewidth 0pt plainfootrulewidth 0pt lhead[\fancyplain{}{\sl\rightmark}]{\fancyplain{}{\sl\leftmark}} i.e. empty on ``plain'' pages \rightmark on even, \leftmark on odd pages chead{} rhead[\fancyplain{}{\sl\leftmark}]{\fancyplain{}{\sl\rightmark}} i.e. empty on ``plain'' pages \leftmark on even, \rightmark on odd pages lfoot{} cfoot{\rm\thepage} % page number rfoot{} xamples: o put two lines containing the section title and the subsection title n the righthandside corner, use: documentstyle[fancyheadings]{article} pagestyle{fancy} renewcommand{\sectionmark}[1]{\markboth{#1}{}} renewcommand{\subsectionmark}[1]{\markright{#1}} rfoot{\leftmark\\\rightmark} he following definitions give an approximation of the style used in the aTeX book: documentstyle[fancyheadings]{book} pagestyle{fancyplain} addtolength{\headwidth}{\marginparsep} addtolength{\headwidth}{\marginparwidth} renewcommand{\chaptermark}[1]{\markboth{#1}{#1}} % remember chapter title renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}} % section number and title lhead[\fancyplain{}{\bf\thepage}]{\fancyplain{}{\bf\rightmark}} rhead[\fancyplain{}{\bf\leftmark}]{\fancyplain{}{\bf\thepage}} cfoot{} sing section titles etc. in the headers and/or footers: ou can't just change the header and/or footer fields in the middle of some ext (e.g. after a section header). This is because TeX may have processed bit more text before deciding to make up the page. It may have passed a ection beginning, causing the wrong title on the page. TeX has a echanism called 'marks' to solve this problem. There is in LaTeX a leftmark and a \rightmark. Usually \leftmark is a chapter title and rightmark is a section title. To set the marks there are two commands: markboth{L}{R} sets the \leftmark to L and the rightmark to R, and rightmark{R} sets only the rightmark to R. he default definitions of \section etc. do this already for you. n example follows: left page right page --------- ---------- CHAPTER 1. Introduction | 1.2 Some section 3 ----------------------------------- | ----------------------------------------- | ext | more text ext | more text ext | more text | | | his can be easily done with fancyheadings as follows: pagestyle{fancy} setlength{\headrulewidth}{1pt} lhead[\rm\thepage]{\sl\rightmark} rhead[\sl\leftmark]{\rm\thepage} his specifies that on even pages (the [] parts) the leftheadpart is page umber and rightheadpart is \leftmark, which is the chapter title (because that s given as the left argument of \markboth (see page 162 of the LaTeX book) n odd pages (the parts between {}) the leftheadpart is \rightmark (which s the last section title because that is given as argument to \markright see the same page), and the rightheadpart is the page no. ow suppose you don't want the section number and you want the section itle in upper case: ou add the following to your preamble: renewcommand{\sectionmark}[1]{\markright{\uppercase{#1}}} r if you don't want the chapter number but only the chapter title (not in ppercase): renewcommand{\chaptermark}[1]{\markboth{#1}{ }} ote: the parameter in both cases is the (section|chapter) title. NOWN PROBLEMS: ometimes you will get a warning message from LaTeX concerning ``overfull box during output''. In this case you have to increase the \headheight or footskip lengths or both (with \addtolength or \setlength). iet* van Oostrum, Dept of Computer Science, Utrecht University, adualaan 14, P.O. Box 80.089, 3508 TB Utrecht, The Netherlands. elephone: +31 30 531806 Uucp: uunet!mcsun!ruuinf!piet elefax: +31 30 513791 Internet: piet@cs.ruu.nl (*`Pete')